﻿//------------------------------------------------------------------------------
// System Name:    Customer Service Platform
// Component:      CIO RoleManagement Page
// Created By:     Tingrong Shi (trshi@wicresoft.com)
// Created Date:   2011-1-27
//------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ASB.CC.Business.CIS;
using ASBCC.Business;
using ASBCC.Database.EntityFramework;

namespace BEGDC.CC.Web.CIS2.Overseas.Admin
{
    public partial class RoleManagement : EntityPage
    {
        /// <summary>
        /// CIO Role Management
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected override EntityDataSource EntitySource
        {
            get { return this.EntityRole; }
        }

        protected override TextBox EntitySearchTxt
        {
            get { return this.SearchText; }
        }

        protected override Button EntityAddBtn
        {
            get { return this.BtnAdd; }
        }

        protected override Button EntitySearchBtn
        {
            get { return this.Searchbtn; }
        }
        protected override Button EntityClearBtn
        {
            get { return this.Cleanbtn; }
        }

        protected override GridView EntityGrid
        {
            get { return this.GVRoles; }
        }

        protected override DetailsView EntityDetails
        {
            get { return this.DVRole; }
        }

        protected override void OnEntityDisabling(int entityKey)
        {
            RoleManagementHelper.SetRoleDisabled(entityKey);
            GlobalHelper.LogOperation(this.User.Identity.Name, SystemModule.CIO, "RoleManagement disabled. id=" + entityKey + "; name=" + RoleManagementHelper.getName(entityKey));
        }

        protected override string GetEntityWhereExpression(string keyword)
        {
            return "(it.Name like N'%" + EntitySearchTxt.Text + "%')";
        }

        protected override void OnEntityInserting(EntityDataSourceChangingEventArgs e)
        {
            var dc = e.Context;
            var role = e.Entity as ASBCC.Database.EntityFramework.Role;
            var pages = this.Request.Form["pagecheck"];
            var menus = this.Request.Form["menucheck"];
            var countries = this.Request.Form["countrycheck"];
            RoleManagementHelper.OnRoleInsertingCIO(dc, role, pages, menus, countries);
        }

        protected override void OnEntityUpdating(EntityDataSourceChangingEventArgs e)
        {
            var dc = e.Context;
            var role = e.Entity as Role;
            var pages = this.Request.Form["pagecheck"];
            var menus = this.Request.Form["menucheck"];
            var countries = this.Request.Form["countrycheck"];
            RoleManagementHelper.OnRoleUpdatingCIO(dc, role, pages, menus, countries);
        }



        protected void EntityRole_Inserted(object sender, EntityDataSourceChangedEventArgs e)
        {
            var dc = e.Context;
            var role = e.Entity as Role;
            var pages = LogInfoHelper.GetPageWithRole(role.RoleID);
            var menus = LogInfoHelper.GetMenuWithRole(role.RoleID);
            var countries = LogInfoHelper.GetCountryWithRole(role.RoleID);
            GlobalHelper.LogOperation(this.User.Identity.Name, SystemModule.CIO, "RoleManagement inserted. id=" + role.RoleID + "; name=" + role.Name + "; description=" + role.Description + "; isAdmin=" + role.IsAdmin + "; page=" + pages + "; menu=" + menus + "; country=" + countries);
        }

        protected void EntityRole_Updated(object sender, EntityDataSourceChangedEventArgs e)
        {
            var dc = e.Context;
            var role = e.Entity as Role;
            var pages = LogInfoHelper.GetPageWithRole(role.RoleID);
            var menus = LogInfoHelper.GetMenuWithRole(role.RoleID);
            var countries = LogInfoHelper.GetCountryWithRole(role.RoleID);
            GlobalHelper.LogOperation(this.User.Identity.Name, SystemModule.CIO, "RoleManagement updated. id=" + role.RoleID + "; name=" + role.Name + "; description=" + role.Description + "; isAdmin=" + role.IsAdmin + "; page=" + pages + "; menu=" + menus + "; country=" + countries);
        }

    }
}
